package top.xiaoshuaila.moments.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.xiaoshuaila.moments.pojo.RespBean;
import top.xiaoshuaila.moments.pojo.Users;
import top.xiaoshuaila.moments.service.FocuService;
import top.xiaoshuaila.moments.utils.Usersutils;

import java.util.Arrays;

@Controller
@RequestMapping("focu")
@Api(tags = "关注相关接口")
public class FocuController {
    @Autowired
    private FocuService focuService;
    @GetMapping("getfans")
    @ResponseBody
    @ApiOperation("获取粉丝列表")
    public RespBean getfans(long vid,int page){
        Users users= Usersutils.getuser();
        return focuService.getfans(users.getId(),vid,page);
    }
    @PutMapping("pinbi")
    @ResponseBody
    @ApiOperation("屏蔽用户")
    public RespBean pinbi(long vid){
        boolean ispinbi=focuService.ispinbi(Usersutils.getuser().getId(),vid);
        if(!ispinbi)focuService.setblack(Usersutils.getuser().getId(),vid);
        else focuService.removeblack(Usersutils.getuser().getId(),vid);
        return RespBean.success("success",!ispinbi);
    }
    @PutMapping("guanzhu")
    @ResponseBody
    @ApiOperation("关注用户")
    public RespBean guanzhu(long vid){
        int ispinbi=focuService.guanzhu(Usersutils.getuser().getId(),vid);
        int fan=ispinbi/2;
        int focuto=ispinbi%2;
        System.out.println(fan+":"+focuto);
        if(focuto==1)
            focuService.removefocuto(Usersutils.getuser().getId(),vid);
        else focuService.addfocuto(Usersutils.getuser().getId(),vid,Usersutils.getuser().getRealname());
        return  RespBean.success("success",new int[]{fan,1-focuto});
    }
    @GetMapping("getfocuto")
    @ResponseBody
    @ApiOperation("获取关注列表")
    public RespBean getfocuto(long vid,int page){
        Users users= Usersutils.getuser();
        return focuService.getfocuto(users.getId(),vid,page);
    }
    @GetMapping("gettotalfocuto")
    @ResponseBody
    @ApiOperation("获取关注总人数")
    public RespBean gettotalfocuto(long vid){
        return RespBean.success("success",focuService.gettotalfocuto(Usersutils.getuser().getId(),vid)) ;
    }
    @GetMapping("gettotalfans")
    @ResponseBody
    @ApiOperation("获取粉丝总人数")
    public RespBean gettotalfans(long vid){
        return RespBean.success("success",focuService.gettotalfans(Usersutils.getuser().getId(),vid)) ;
    }
}
